package com.campus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.campus.dao.SysUserMapper;
import com.campus.entry.SysUser;
import com.campus.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SysUserServiceImpl implements SysUserService {
    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 新增一名用户
     * @param sysUser
     */
    @Override
    public void saveSysUser(SysUser sysUser) {
        sysUserMapper.insert(sysUser);
    }

    /**
     * 根据Id查询用户
     * @param sysUserId
     * @return {@link SysUser }
     */
    @Override
    public SysUser getSysUserById(Integer sysUserId) {
        LambdaQueryWrapper<SysUser> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper
                .eq(SysUser::getId,sysUserId);
        return sysUserMapper.selectOne(lambdaQueryWrapper);
    }

    /**
     * 根据用户名查询用户
     * @param loginName
     * @return {@link SysUser }
     */
    @Override
    public SysUser getSysUserByName(String loginName) {
         LambdaQueryWrapper<SysUser> lambdaQueryWrapper=new LambdaQueryWrapper<>();
         lambdaQueryWrapper
                 .eq(SysUser::getLoginName,loginName);
         return sysUserMapper.selectOne(lambdaQueryWrapper);
    }

}
